package com.bondar.RestLogin.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import com.bondar.RestLogin.entities.User;
import com.bondar.RestLogin.repositories.UserRepository;
import com.bondar.RestLogin.services.UserService;

public class MyUserDetailsService implements UserDetailsService {
	
//	@Autowired UserService userService;

	@Override
	public UserDetails loadUserByUsername(String name)
			throws UsernameNotFoundException {

        UserService userService = new UserService();

		User user = userService.findUserByName(name);

		if (user == null) {
			throw new UsernameNotFoundException("User not found");
		}
		
		return user;
	}

}
